;;; GNU Guix --- Functional package management for GNU
;;;
;;; Copyright © 2022 Bird <birdsite@airmail.cc>
;;; Copyright © 2022 Charles Jackson <charles.b.jackson@protonmail.com>
;;;
;;; This file is not part of GNU Guix.
;;;
;;; GNU Guix is free software; you can redistribute it and/or modify it
;;; under the terms of the GNU General Public License as published by
;;; the Free Software Foundation; either version 3 of the License, or (at
;;; your option) any later version.
;;;
;;; GNU Guix is distributed in the hope that it will be useful, but
;;; WITHOUT ANY WARRANTY; without even the implied warranty of
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;;; GNU General Public License for more details.
;;;
;;; You should have received a copy of the GNU General Public License
;;; along with GNU Guix.  If not, see <http://www.gnu.org/licenses/>.

(define-module (guixrus packages emulators)
  #:use-module ((guix licenses) #:prefix license:)
  #:use-module (gnu packages assembly)
  #:use-module (gnu packages audio)
  #:use-module (gnu packages compression)
  #:use-module (gnu packages game-development)
  #:use-module (gnu packages gettext)
  #:use-module (gnu packages gl)
  #:use-module (gnu packages gnome)
  #:use-module (gnu packages gtk)
  #:use-module (gnu packages image)
  #:use-module (gnu packages pkg-config)
  #:use-module (gnu packages sdl)
  #:use-module (gnu packages video)
  #:use-module (gnu packages wxwidgets)
  #:use-module (gnu packages)
  #:use-module (guix build utils)
  #:use-module (guix build-system cmake)
  #:use-module (guix build-system glib-or-gtk)
  #:use-module (guix download)
  #:use-module (guix gexp)
  #:use-module (guix git-download)
  #:use-module (guix packages)
  #:use-module (guix utils))

(define-public gnusim8085
  (package
   (name "gnusim8085")
   (version "1.4.1")
   (source
    (origin
     (method url-fetch)
     (uri (string-append
	   "https://github.com/srid/GNUSim8085/releases/download/"
           version "/" name "-" version ".tar.gz"))
     (sha256
      (base32
       "05x0is0ckagb3r74p6lw9b8nqrrh7q2v4jvc4cnhljchz9x7kw2a"))))
   (native-inputs (list pkg-config))
   (inputs (list gtksourceview-3 adwaita-icon-theme ))
   (build-system glib-or-gtk-build-system)
   (home-page "https://gnusim8085.srid.ca")
   (synopsis "Graphical simulator, assembler and debugger for the
Intel 8085 microprocessor")
   (description "GNUSim8085 is a graphical simulator,
assembler and debugger for the Intel 8085 microprocessor
in GNU/Linux and Windows.
@itemize
@item A simple editor component with syntax highlighting.
@item A keypad to input assembly language instructions with appropriate arguments.
@item Easy view of register contents.
@item Easy view of flag contents.
@item Hexadecimal <–> Decimal converter.
@item View of stack, memory and I/O contents.
@item Support for breakpoints for program debugging.
@item Stepwise program execution.
@item One click conversion of assembly program to opcode listing.
@item Printing support.
@item UI translated in various languages.
@end itemize")
   (license license:gpl2)))

(define-public visualboyadvance-m
  (package
    (name "visualboyadvance-m")
    (version "2.1.4")
    (source
     (origin
      (method git-fetch)
      (uri (git-reference
            (url
             "https://github.com/visualboyadvance-m/visualboyadvance-m/")
            (commit (string-append "v" version))))
      (file-name (git-file-name name version))
      (sha256
       (base32
        "1kgpbvng3c12ws0dy92zc0azd94h0i3j4vm7b67zc8mi3pqsppdg"))
      (patches
       (parameterize
           ((%patch-path
             (map
              (lambda (directory)
                (string-append directory "/guixrus/packages/patches"))
              %load-path)))
         (search-patches "visualboyadvance-m-fix-rpath.patch")))))
    (build-system cmake-build-system)
    (arguments
     (list
      #:build-type "Release"
      #:tests? #f ;no tests
      #:configure-flags
      #~(list "-DENABLE_SSP=ON" "-DENABLE_ONLINEUPDATES=OFF"
              (string-append "-DCMAKE_PREFIX_PATH="
                             #$(this-package-input "wxwidgets")))
      #:phases
      #~(modify-phases %standard-phases
          (add-after 'unpack 'set-c-compiler
            (lambda _
              (substitute*
               "cmake/HostCompile.cmake"
               ((" cc ")
                (string-append
                 " " #$(cc-for-target)
                 " "))))))))
    (native-inputs (list gettext-minimal nasm pkg-config zip))
    (inputs
     (list ffmpeg
           gtk+
           libpng
           mesa
           openal
           sdl2
           sfml
           wxwidgets
           zlib))
    (home-page "https://vba-m.com/")
    (synopsis "Performant Nintendo Gameboy emulator")
    (description
     "Visual Boy Advance M is an emulator of the Game Boy, Game Boy
Color, and Game Boy Advance handheld game consoles.")
    (license license:gpl3+)))
